package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.ui.mvp.contract.BrowserHistoryContract;

import javax.inject.Inject;

import io.reactivex.functions.Consumer;

public class BrowserHistoryPresenter extends BasePresenter<BrowserHistoryContract.Model, BrowserHistoryContract.View> {


    @Inject
    public BrowserHistoryPresenter(BrowserHistoryContract.Model model, BrowserHistoryContract.View rootView) {
        super(model, rootView);
    }


    public void delSingleBrowserHistory(String time, String url) {
        addSubscribe(mModel.delSingleBrowserHistory(time, url)
                .compose(RxUtils.<Boolean>rxSchedulerHelper())
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        mView.onDelSingle(aBoolean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));

    }


    public void delAllBrowserHistory() {
        addSubscribe(mModel.delAllBrowserHistory()
                .compose(RxUtils.<Boolean>rxSchedulerHelper())
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        mView.onDelAll(aBoolean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));

    }


}


